<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css" integrity="sha256-2H3fkXt6FEmrReK448mDVGKb3WW2ZZw35gI7vqHOE4Y=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"example.com","root":"/","images":"/images","scheme":"Muse","version":"8.6.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}}</script><script src="/js/config.js"></script>
<meta name="description" content="聊聊spring？谈谈Spring IOC的理解，原理与实现？总： IOC:控制反转，原来的对象是由使用者控制创建的，有了spring后，可以把整个对象交给Spring 来帮我们信息管理创建； DI：依赖注入，把对应的属性的值注入到具体的对象中，@Autowired ,populateBean 完成属性值的注入； spring容器：存储对象，使用map对象存储，在spring中一般存在三级缓存，">
<meta property="og:type" content="article">
<meta property="og:title" content="面试题">
<meta property="og:url" content="http://example.com/2021/08/24/interview/index.html">
<meta property="og:site_name" content="风轻云淡">
<meta property="og:description" content="聊聊spring？谈谈Spring IOC的理解，原理与实现？总： IOC:控制反转，原来的对象是由使用者控制创建的，有了spring后，可以把整个对象交给Spring 来帮我们信息管理创建； DI：依赖注入，把对应的属性的值注入到具体的对象中，@Autowired ,populateBean 完成属性值的注入； spring容器：存储对象，使用map对象存储，在spring中一般存在三级缓存，">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/wqqszz/blogImg/raw/master/img/bean.jpg">
<meta property="og:image" content="c:/Users/16406/Desktop/1647326853(1).png">
<meta property="og:image" content="https://gitee.com/wqqszz/blogImg/raw/master/img/image-20210828215610486.png">
<meta property="og:image" content="https://gitee.com/wqqszz/blogImg/raw/master/img/%E6%8D%95%E8%8E%B7.PNG">
<meta property="article:published_time" content="2021-08-24T13:22:38.000Z">
<meta property="article:modified_time" content="2022-03-15T07:09:53.875Z">
<meta property="article:author" content="WQQ">
<meta property="article:tag" content="风">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/wqqszz/blogImg/raw/master/img/bean.jpg">


<link rel="canonical" href="http://example.com/2021/08/24/interview/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://example.com/2021/08/24/interview/","path":"2021/08/24/interview/","title":"面试题"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>面试题 | 风轻云淡</title>
  




  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
	<!-- 页面点击小红心 -->
	<script type="text/javascript" src="/js/src/clicklove.js"></script>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">风轻云淡</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">清风吹拂，白云淡淡</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-首页"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-关于"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li>
        <li class="menu-item menu-item-标签"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li>
        <li class="menu-item menu-item-分类"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%81%8A%E8%81%8Aspring%EF%BC%9F%E8%B0%88%E8%B0%88Spring-IOC%E7%9A%84%E7%90%86%E8%A7%A3%EF%BC%8C%E5%8E%9F%E7%90%86%E4%B8%8E%E5%AE%9E%E7%8E%B0%EF%BC%9F"><span class="nav-number">1.</span> <span class="nav-text">聊聊spring？谈谈Spring IOC的理解，原理与实现？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%AF%B4%E8%AF%B4bean%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%EF%BC%9F"><span class="nav-number">2.</span> <span class="nav-text">说说bean的生命周期？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Spring-Bean%E7%9A%84%E5%BE%AA%E7%8E%AF%E4%BE%9D%E8%B5%96%EF%BC%9F"><span class="nav-number">3.</span> <span class="nav-text">Spring Bean的循环依赖？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%B8%89%E7%BA%A7%E7%BC%93%E5%AD%98"><span class="nav-number">4.</span> <span class="nav-text">三级缓存</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#FactoryBean-%E5%92%8CBeanFactory%E5%8C%BA%E5%88%AB%EF%BC%9A"><span class="nav-number">5.</span> <span class="nav-text">FactoryBean 和BeanFactory区别：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ApplicationContext-%E5%92%8C-BeanFactory%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="nav-number">6.</span> <span class="nav-text">ApplicationContext 和 BeanFactory的区别</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F"><span class="nav-number">7.</span> <span class="nav-text">设计模式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#SpringMVC-%E6%A1%86%E6%9E%B6%EF%BC%9F"><span class="nav-number">8.</span> <span class="nav-text">SpringMVC 框架？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#SpringMvc%E5%8E%9F%E7%90%86%E6%B5%81%E7%A8%8B%EF%BC%9A"><span class="nav-number">9.</span> <span class="nav-text">SpringMvc原理流程：</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-overview">
            <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="WQQ"
      src="/images/aaa.jpg">
  <p class="site-author-name" itemprop="name">WQQ</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives">
          <span class="site-state-item-count">14</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://gitee.com/wqqszz" title="GitHub → https:&#x2F;&#x2F;gitee.com&#x2F;wqqszz" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="QQ:1640611853@qq.com" title="E-Mail → QQ:1640611853@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



          </div>
        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/08/24/interview/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/aaa.jpg">
      <meta itemprop="name" content="WQQ">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="风轻云淡">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          面试题
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-08-24 21:22:38" itemprop="dateCreated datePublished" datetime="2021-08-24T21:22:38+08:00">2021-08-24</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2022-03-15 15:09:53" itemprop="dateModified" datetime="2022-03-15T15:09:53+08:00">2022-03-15</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <ol>
<li><h4 id="聊聊spring？谈谈Spring-IOC的理解，原理与实现？"><a href="#聊聊spring？谈谈Spring-IOC的理解，原理与实现？" class="headerlink" title="聊聊spring？谈谈Spring IOC的理解，原理与实现？"></a>聊聊spring？谈谈Spring IOC的理解，原理与实现？</h4><p>总：</p>
<p>IOC:控制反转，原来的对象是由使用者控制创建的，有了spring后，可以把整个对象交给Spring 来帮我们信息管理创建；</p>
<p>DI：依赖注入，把对应的属性的值注入到具体的对象中，@Autowired ,populateBean 完成属性值的注入；</p>
<p><strong>spring容器：存储对象，使用map对象存储</strong>，在spring中一般存在三级缓存，singletonObject 存放完整的bean对象，整个bean的生命周期，<strong>从bean的创建到bean的使用到bean的销毁都是由spring容器管理的。</strong></p>
<p>分：</p>
<p>①，一般聊ioc容器的时候要涉及到容器的创建过程：ioc容器创建的时候，有一个最上层的根接口 beanFactory,没有提供对应的子类实现，DefaultListableBeanFactory,（）</p>
<p>AOP: 面向切面编程，动态代理实现（动态代理有两种：jdk，cglib）</p>
</li>
</ol>
<p>   扩展：什么是三级缓存？bean生命周期？还有其他的map类型吗？</p>
<ol start="2">
<li><h4 id="说说bean的生命周期？"><a href="#说说bean的生命周期？" class="headerlink" title="说说bean的生命周期？"></a>说说bean的生命周期？</h4><p><img src="https://gitee.com/wqqszz/blogImg/raw/master/img/bean.jpg"></p>
<p><strong>①：实例化bean:</strong> 反射的方式生成对象；（可以引来反射一系列问题）</p>
<p><strong>②：填充bean属性：</strong>关键的方法 populateBean(),循环依赖的问题（三级缓存）；</p>
<p><strong>③：调用Aware相关接口的方法：</strong>invokeAwareMethod（完成BeanName,BeanFactory,BeanClassLoader对象的属性设置）；</p>
<p><strong>④：调用BeanPostProcessor中的前置处理方法</strong>：使用比较多的有（ApplicationContextPostProcessor 设置ApplicationContext, Environment 等对象）；</p>
<p><strong>⑤：调用initmethod方法：</strong>invokeinitmethod()， 判断是否实现了initializingBean接口，如果有，调用afterPropertiesSet方法，没有就不调用；</p>
<p><strong>⑥：调用 BeanPostProcessor 的后置处理方法：</strong>spring的aop就是在此处实现的；</p>
<p><strong>⑦：获取完整的对象</strong>，可以通过getBean的方式来进行对象的获取；</p>
<p><strong>⑧：销毁</strong>：判断是否实现了DispoableBean接口；调用DestoryMethod方法；</p>
</li>
<li><h4 id="Spring-Bean的循环依赖？"><a href="#Spring-Bean的循环依赖？" class="headerlink" title="Spring Bean的循环依赖？"></a>Spring Bean的循环依赖？</h4><p>什么是循环依赖：  </p>
<p>​        类A通过构造函数注入类B的的实例中，而类Bt通过构造函数注入类A中，即将类A和类B的bean配置为相互注入。</p>
<p><img src="C:\Users\16406\Desktop\1647326853(1).png" alt="1647326853(1)"></p>
<p>如何解决SpringBean的循环依赖问题：</p>
<p>​     解决的方法：就是不使用基于构造函数的依赖注入，可以通过如下两种方法：</p>
<p>​    ①，在实例变量上加上@Autowired注解，让Spring自行在合适的时机注入，而非初始化类的时候就注入。</p>
<p>​    ②，用基于setter方法的依赖注入取代基于构造函数的依赖注入。</p>
<p>​    解决循环依赖机制：根据Spring框架内定义的<strong>三级缓存来实现的</strong>，（前提是：bean是单例的）（Spring默认的bean是单例的，对于单例的Bean之间的循环依赖问题，Spring是可以通过三级缓存进行解决的。）</p>
<p>​</p>
</li>
<li><h4 id="三级缓存"><a href="#三级缓存" class="headerlink" title="三级缓存"></a>三级缓存</h4><p>singletonObjects : 一级缓存，里面放置的是实例化好的单例对象。</p>
<p>earlySingletonObjects: 二级缓存，里面存放的是提前曝光的单例对象。</p>
<p>singletonFactories: 三级缓存，里面存放的是要被实例化的对象的对象工厂。</p>
<p>​</p>
<p>​</p>
</li>
<li><h4 id="FactoryBean-和BeanFactory区别："><a href="#FactoryBean-和BeanFactory区别：" class="headerlink" title="FactoryBean 和BeanFactory区别："></a>FactoryBean 和BeanFactory区别：</h4><p>BeanFactory 和 FactoryBean 其实没有什么可以比较的，只是名字相近，所以有时候会拿出来进行比较，BeanFactory 是提供了IOC容器最基本的形式，给具体的 IOC 容器的实现提供了规范，</p>
<p>FactoryBean 在 IOC 容器的基础上给 Bean的实现加上了一个简单工厂模式和装饰模式，我们可以在 getObject() 方法中灵活配置，其实在spring 源码中有很多FactoryBean 的实现类，想要深入准确的理解 FactoryBean ，只能读取Spring 源码了。。。。。</p>
</li>
</ol>
<ol start="6">
<li><h4 id="ApplicationContext-和-BeanFactory的区别"><a href="#ApplicationContext-和-BeanFactory的区别" class="headerlink" title="ApplicationContext 和 BeanFactory的区别"></a>ApplicationContext 和 BeanFactory的区别</h4><p>​</p>
</li>
<li><h4 id="设计模式"><a href="#设计模式" class="headerlink" title="设计模式"></a>设计模式<img src="https://gitee.com/wqqszz/blogImg/raw/master/img/image-20210828215610486.png" alt="image-20210828215610486"></h4></li>
<li><h4 id="SpringMVC-框架？"><a href="#SpringMVC-框架？" class="headerlink" title="SpringMVC 框架？"></a>SpringMVC 框架？</h4><h4 id="SpringMvc原理流程："><a href="#SpringMvc原理流程：" class="headerlink" title="SpringMvc原理流程："></a>SpringMvc原理流程：</h4></li>
</ol>
<p><img src="https://gitee.com/wqqszz/blogImg/raw/master/img/%E6%8D%95%E8%8E%B7.PNG" alt="捕获"></p>

    </div>

    
    
    
	
	<div>
		
			<div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>
		
	</div>

    <footer class="post-footer">

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2021/08/13/docker/" rel="prev" title="Docker">
                  <i class="fa fa-chevron-left"></i> Docker
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2021/11/04/%E6%A1%86%E6%9E%B6/" rel="next" title="框架">
                  框架 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">WQQ</span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/muse/" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>

  




  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
